// 
// Decompiled by Procyon v0.5.36
// 

package com.cyberfend.cyfsecurity;

import java.util.*;
import android.app.*;
import com.cyberfend.cyfsecurity.b.*;
import android.hardware.*;
import android.os.*;

final class j extends java.util.Observable implements android.hardware.SensorEventListener
{
    android.hardware.SensorManager a;
    android.hardware.Sensor b;
    android.hardware.Sensor c;
    long d;
    boolean e;
    boolean f;
    boolean g;
    boolean h;
    boolean i;
    private float l;
    private float m;
    private float n;
    private float o;
    private float p;
    private float q;
    private float r;
    private float s;
    private float t;
    float j;
    private final float[] u;
    int k;
    
    public j(final android.app.Application application) {
        this.d = 0L;
        this.e = false;
        this.f = false;
        this.g = false;
        this.h = false;
        this.i = false;
        this.l = -1.0f;
        this.m = -1.0f;
        this.n = -1.0f;
        this.o = -1.0f;
        this.p = -1.0f;
        this.q = -1.0f;
        this.r = -1.0f;
        this.s = -1.0f;
        this.t = -1.0f;
        this.j = 0.0f;
        this.u = new float[] { 0.0f, 0.0f, 0.0f };
        this.k = 0;
        try {
            this.a = (android.hardware.SensorManager)application.getSystemService("sensor");
        }
        catch (java.lang.Exception ex) {
            com.cyberfend.cyfsecurity.b.a.c("MotionListener", "Exception on getting sensor service", ex);
            com.cyberfend.cyfsecurity.f.a(ex);
        }
    }
    
    public final void a() throws java.lang.Exception {
        new java.lang.StringBuilder("Unregister Gyroscope ").append(this.f).append(" and Accelerometer ").append(this.e);
        if (this.f) {
            this.a.unregisterListener((android.hardware.SensorEventListener)this, this.c);
            this.f = false;
        }
        if (this.e) {
            this.a.unregisterListener((android.hardware.SensorEventListener)this, this.b);
            this.e = false;
        }
        this.i = false;
    }
    
    public final void onAccuracyChanged(final android.hardware.Sensor sensor, final int accuracy) {
    }
    
    public final void onSensorChanged(final android.hardware.SensorEvent event) {
        try {
            final long uptimeMillis = android.os.SystemClock.uptimeMillis();
            if (!this.i && event.accuracy == 0) {
                com.cyberfend.cyfsecurity.b.a.b("MotionListener", "Unreliable motion sensors data...", new java.lang.Throwable[0]);
                this.i = true;
            }
            final int type = event.sensor.getType();
            new java.lang.StringBuilder("Motion sensor changed elapsed time: ").append(uptimeMillis - this.d).append(", Sensor Type: ").append(type);
            if (type == 4) {
                if (this.f) {
                    this.r = event.values[0];
                    this.s = event.values[1];
                    this.t = event.values[2];
                    this.g = true;
                }
            }
            else if (type == 1 && this.e) {
                this.l = event.values[0];
                this.m = event.values[1];
                this.n = event.values[2];
                final float[] values = event.values;
                float n;
                if (java.lang.Float.isNaN(n = 1.0f / (++this.k / ((java.lang.System.nanoTime() - this.j) / 1.0E9f))) || java.lang.Float.isInfinite(n)) {
                    n = 0.0f;
                }
                final float n2 = 0.18f / (0.18f + n);
                this.u[0] = n2 * this.u[0] + (1.0f - n2) * values[0];
                this.u[1] = n2 * this.u[1] + (1.0f - n2) * values[1];
                this.u[2] = n2 * this.u[2] + (1.0f - n2) * values[2];
                final float[] array2;
                final float[] array = array2 = new float[] { 0.0f, 0.0f, 0.0f };
                array[0] = values[0] - this.u[0];
                array2[1] = values[1] - this.u[1];
                array2[2] = values[2] - this.u[2];
                if (java.lang.Float.isNaN(array2[0]) || java.lang.Float.isInfinite(array2[0])) {
                    array2[0] = 0.0f;
                }
                if (java.lang.Float.isNaN(array2[1]) || java.lang.Float.isInfinite(array2[1])) {
                    array2[1] = 0.0f;
                }
                if (java.lang.Float.isNaN(array2[2]) || java.lang.Float.isInfinite(array2[2])) {
                    array2[2] = 0.0f;
                }
                final float[] array3 = array2;
                this.o = array3[0];
                this.p = array3[1];
                this.q = array3[2];
                this.l *= -1.0f;
                this.m *= -1.0f;
                this.n *= -1.0f;
                this.o *= -1.0f;
                this.p *= -1.0f;
                this.q *= -1.0f;
                this.h = true;
            }
            if (this.g && this.h && (uptimeMillis - this.d >= 100L || com.cyberfend.cyfsecurity.d.l == 1)) {
                new java.lang.StringBuilder("Motion event elapsed time: ").append(uptimeMillis - this.d);
                this.d = uptimeMillis;
                final boolean b = com.cyberfend.cyfsecurity.d.l != 0;
                com.cyberfend.cyfsecurity.d.l = 0;
                this.setChanged();
                new java.lang.StringBuilder("Data: ax:").append(this.l).append(", ay:").append(this.m).append(", az:").append(this.n).append("; agx:").append(this.o).append(", agy:").append(this.p).append(", agz:").append(this.q).append("; gx:").append(this.r).append(", gy:").append(this.s).append(", gz:").append(this.t);
                this.notifyObservers(new com.cyberfend.cyfsecurity.l(this.l, this.m, this.n, this.o, this.p, this.q, this.r, this.s, this.t, this.d, b ? 2 : 1));
                this.g = !this.f;
                this.h = !this.e;
            }
        }
        catch (java.lang.Exception ex) {
            com.cyberfend.cyfsecurity.b.a.b("MotionListener", "Exception in processing motion event", ex);
            com.cyberfend.cyfsecurity.f.a(ex);
        }
    }
}
